package Backtracking;
/*
 * 电话号码的字母组合
 */
import java.util.ArrayList;
import java.util.List;

public class lc17 {

    List<String> list = new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) {
            return list;
        }
        String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        backtracking(digits, numString, 0);
        return list;
    }
    StringBuilder temp = new StringBuilder();
    public void backtracking(String digits, String[] numString, int num) {
        if (num == digits.length()) {
            list.add(temp.toString());
            return;
        }
        String digit = numString[digits.charAt(num) - '0'];
        for (int i = 0; i < digit.length(); i++) {
            temp.append(digit.charAt(i));
            backtracking(digits, numString, num + 1);
            temp.deleteCharAt(temp.length() - 1);
        }
    }

}
